package Service.serviceImpl;

import Dao.daoImpl.EmpDaoImpl;
import Model.Emp;
import Service.UserService;

import java.sql.SQLException;
import java.util.Scanner;

public class EmpService implements UserService {
    EmpDaoImpl empDao = new EmpDaoImpl();

    //查询
    @Override
    public void showEmp() throws SQLException {
        System.out.println("业务逻辑开始了");
        empDao.showEmpDao();
    }

    //删除
    @Override
    public void delEmp(int empId) {
        try {
            empDao.delEmpDao(empId);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    //修改两种方法

    /**
     * System.out.println("1.改姓名");
     * System.out.println("2.该性别");
     * System.out.println("3.改年龄");
     * System.out.println("4.改职务");
     * int menu = scanner.nextInt();
     * switch (menu) {
     * case 1:
     * System.out.println("给改的姓名是:" + emp.get(j).getName());
     * System.out.println("请输入更改的名字");
     * emp.get(j).setName(scanner.next());
     * break;
     * case 2:
     * System.out.println("给改的性别是:" + emp.get(j).getSex());
     * System.out.println("请输入更改的性别");
     * emp.get(j).setSex(scanner.next());
     * case 3:
     * System.out.println("给改的年龄是:" + emp.get(j).getAge());
     * System.out.println("请输入更改的年龄");
     * emp.get(j).setAge(scanner.nextInt());
     * case 4:
     * System.out.println("给改的工作是:" + emp.get(j).getJob());
     * System.out.println("请输入更改的工作");
     * emp.get(j).setJob(scanner.next());
     */
    @Override
    public Boolean updateEmp(int empId1) throws SQLException {
        Scanner scanner = new Scanner(System.in);
        Emp oneDataDao = empDao.findOneDataDao(empId1);
        if (oneDataDao == null) {
            return false;
        } else {
            Emp obj = new Emp();
            System.out.println("你要更新的员工姓名是:" + oneDataDao.getName());
            System.out.print("请输入你要更新的名字是:");
            String s = scanner.nextLine();
            if (s.equals("")) {
                obj.setName(oneDataDao.getName());
            } else {
                obj.setName(s);
            }
//            emp.get(j).setName(scanner.next());
            System.out.println("你要更新的员工性别是:" + oneDataDao.getSex());
            System.out.print("请输入你要更新的性别是:");
            String s1 = scanner.nextLine();
            if (s1.equals("")) {
                obj.setSex(oneDataDao.getSex());
            } else {
                obj.setSex(s1);
            }
//            emp.get(j).setSex(scanner.next());
            System.out.println("你要更新的年龄是:" + oneDataDao.getAge());
            System.out.print("请输入你要更新的年龄是:");
            String s3 = scanner.nextLine();
            if (s3.equals("")) {
                obj.setAge(oneDataDao.getAge());
            } else {
                int a = Integer.parseInt(s3);
                obj.setAge(a);
            }
//            emp.get(j).setAge(scanner.nextInt());
            System.out.println("你要更新的员工工作是:" + oneDataDao.getJob());
            System.out.print("请输入你要更新的工作是:");
            String s4 = scanner.nextLine();
            if (s4.equals("")) {
                obj.setJob(oneDataDao.getJob());
            } else {
                obj.setJob(s4);
            }
            boolean b = empDao.updateEmpDao(obj, empId1);
//            emp.get(j).setJob(scanner.next());
            return b;
        }
    }

    /*增加
                体现员工信息的逻辑层
                @param emp Array 数据集合 地址
                @param user 一条员工信息
             */
    @Override
    public void addEmp(Emp obj) {
        try {
            empDao.addEmpDao(obj);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
